/*
 * Students:
 * Massimiliano Rango - 610826
 * Martina Benedetto - 610962
 * 
 * A.A 2011/2012
 * 
 */ 

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;

/**
 *
 * This class represents the remote object created by the RMIServer. It contains 
 * the NSim results of the NSim simulations. They're collected in a vector and
 * each SimResult is added to the vector thank to the method addResult.
 * 
 * @version 1.0 27 Dec 2011
 * @author Martina Benedetto 
 *
 */

public class Results extends UnicastRemoteObject implements ResultsInterface {
	
	/* Autogenerated field to avoid compilation warning */
        private static final long serialVersionUID = -5930965057463516629L;		
        
	private Vector<SimResultInterface> m_simulationsResults;
	
	public Results() throws RemoteException {
		m_simulationsResults = new Vector<SimResultInterface>();
	}
	
	/**
	 * Add the result of ONE single simulation to the vector of results.
	 * @param res is the SimResult we want to add to the vector
	 */
	public void addResult(SimResultInterface res) throws RemoteException {
		synchronized(this) {
			m_simulationsResults.add(res);
			notifyAll();
		}
	}
	
	public boolean isEmptyResults() {
		return m_simulationsResults.isEmpty();
	}
	
	public SimResultInterface popNextResult() {
		if(!isEmptyResults()) {
			return m_simulationsResults.remove(0);
		}
		return null;
	}
}
